package juc.c_001;/*
   Talk is cheap. Show me the code.
 */

import java.util.concurrent.TimeUnit;

/**
 * @Description 出现异常则锁自动释放
 * @Date 2021/6/6
 * @Author liudl
 */
public class T11 {
    int count = 0;
    public synchronized void m() {
        while (count<20) {
            count++;
            try {
                TimeUnit.MICROSECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " count = " + count);
            if (count == 5) {
                int i1 = count / 0;
            }
        }
    }

    public static void main(String[] args) {
        T11 t11 = new T11();
        new Thread(() -> {
            t11.m();
        },"t1").start();
        new Thread(() -> {
            t11.m();
        }, "t2").start();
    }
}
